<?php

putenv("DISPLAY=:1");
putenv("XAUTHORITY=/var/www/.Xauthority");

ini_set('display_errors', 1);
error_reporting(E_ALL);

include_once 'Bot.php';
include_once 'Api.php';

$svn     = $argv[1];
$revId   = $argv[2];
$comment = $argv[3];

$dbus = new Dbus(Dbus::BUS_SESSION, true);
$n = $dbus->createProxy('com.Skype.API', '/com/Skype', 'com.Skype.API');
$n->Invoke('NAME SEND_CHANGE');
$n->Invoke('PROTOCOL 8');
$dbus->registerObject('/com/Skype/Client', 'com.Skype.API.Client', 'Bot');

if ($svn) {
    $user = Bot::getInstance()->getUserBySvn($svn);
    $msg = '=== [' . $revId . '] ===' ."\n";
    $msg .= 'commiter: ' . $svn . "\n" ;
    $msg .= 'log: ' . iconv("WINDOWS-1251","UTF-8", urldecode($comment)) . "\n" ;

    if ($msg) {
        Bot::getInstance()->sendNotifyToSkype('fs.SVN', $msg);
    } else {
        echo "NO SENDING 2";
    }
} else {
    echo "NO SENDING SVN NOTIFY";
}

exit();